package com.swjd.jingle.activity;

import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import com.swjd.jingle.R;

import java.util.Timer;
import java.util.TimerTask;

import butterknife.BindView;
import butterknife.OnClick;

public class WelcomeActivity extends BaseActivity implements View.OnClickListener {

    @BindView(R.id.tv_time)
    TextView tvTime;
    @BindView(R.id.tv_skip)
    TextView tvSkip;
    private int time = 3;
    private Timer timer1, timer2;

    @Override
    public void initialize() {
        //通过SharedPreferences储存应用是否第一次进入
        boolean guide = sp.getBoolean("guide", false);
        if (!guide) {
            //用户首次进入则进入引导页
            startActivity(new Intent(context, GuideActivity.class));
            this.finish();
        } else {
            timer1 = new Timer();
            timer1.schedule(new TimerTask() {
                @Override
                public void run() {
                    tvTime.setText(time + "");
                    --time;
                }
            }, 0, 1000);
            timer2 = new Timer();
            timer2.schedule(new TimerTask() {
                @Override
                public void run() {
                    startActivity(new Intent(context, MainActivity.class));
                    timer1.cancel();
                    finish();
                }
            }, 2000);
        }
    }

    @Override
    public void initView() {
    }

    @Override
    public void initData() {

    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_welcome;
    }

    @Override
    @OnClick({R.id.tv_skip})
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_skip:
                timer1.cancel();
                timer2.cancel();
                tvSkip.setEnabled(false);
                startActivity(new Intent(context, MainActivity.class));
                finish();
                break;
        }
    }

}
